home *** CD-ROM | disk | FTP | other *** search
/ El Mac 7 / El Mac 7.iso / Actualizaciones / BBEdit 3.5.2 Update / HTML Tools Documentation / docs / Custom Markup Info.txt < prev    next >
Encoding:
Text File  |  1995-11-22  |  15.5 KB  |  429 lines  |  [TEXT/R*ch]

  1. User's Markup Tool - part of the BBEdit HTML Tools package.
  2. ©1994 Lindsay Davies
  3. email: Lindsay.Davies@sheffield.ac.uk
  4.  
  5.  
  6. Status:                Semi-informal release pending feedback :-)
  7. Last updated:        2/8/95
  8.             
  9.  
  10.  
  11. CUSTOM MARKUP ROUTINES
  12. -------------------------------------------------------------------------
  13.  
  14. This tool will help those people who regularly have to process or edit HTML
  15. documents. It allows you to define up to 20 'styles' that can be applied
  16. to any part of your text.
  17.  
  18. (Background note: This tool started off with a rather more limited
  19. scope in mind. It seems that in developing it, it has changed from being
  20. a tool for storing simple markup styles to a simple macro package. So bear
  21. in mind that macros weren't its original objective, and forgive its
  22. rather clumsy design!).
  23.  
  24.  
  25.  
  26.  
  27. Introduction:
  28. -------------------------------------------------------------------------
  29.  
  30. To define your style, bring up the 'User Styles' tool, and you will see a
  31. number of undefined buttons. To create a label and definition for your
  32. style, simply click on a button and fill out the 'Label' and 'Definition'
  33. fields (The definition field isn't yet labelled).
  34.  
  35. The best way to introduce the tool is with a worked-through example.
  36. Suppose that we have a style for certain section headings that requires
  37. marking up like this:
  38.  
  39.    <H2><I>My Heading</I></H2>
  40.    <HR>
  41.  
  42. This would normally involve 4 operations (one for each of the
  43. tags involved, and one for the return before the <HR> tag).
  44.  
  45. To define your own style to do this automatically, Make your definition
  46. as follows:
  47.  
  48.    <H2><I>…</I></H2>\r<HR>
  49.    
  50. Working through this example we have the opening Heading tag,
  51. the opening Italic tag, and then we have the important part, the
  52. ellipsis. You type the ellipsis by using Option-; not by typing 3
  53. periods. The ellipsis is the character that represents your current
  54. selection. All text before the ellipsis goes before your selection, and
  55. of course, everything after the ellipsis follows after the current
  56. selection.
  57.  
  58. So after the ellipsis we have the closing Italic and Heading tags.
  59. Following on from this is \r which represents a return character.
  60. Finally we have the horizontal rule tag.
  61.  
  62. So if you select your text, eg
  63.  
  64.     My Heading
  65.     
  66. ...and then apply this style to it, it will be marked up exactly as the
  67. first example was, but in one operation.
  68.  
  69. If you have a number of headings to mark up, then you won't want to keep
  70. going to the menu to do this. You can use the 'Repeat Macro' command
  71. (command-short-option-T) to just redo the last operation.
  72.  
  73. OK, that's the basics. If you don't want to know any more, then save the
  74. next bit till later! You may however wish to have a look at the examples
  75. at the end of this document, which will give you an idea of the sorts of
  76. things that you can do.
  77.  
  78.  
  79.  
  80. Intermediate Stuff:
  81. -------------------------------------------------------------------------
  82. In your style definition, you can put in certain placeholders. You have
  83. already met the one for a return - \r. There are some others available to
  84. help you with your creative impluses:
  85.  
  86.   Placeholder             Function
  87.      \r                    Inserts return character
  88.      \t                    Inserts tab character
  89.      \c                    Inserts clipboard (eg whatever has been
  90.                              most recently copied or cut.
  91.      \b                    Inserts the contents of the buffer (more about this later)
  92.      \…                    Inserts an ellipsis
  93.      \\                    Inserts a slash
  94.      \!                    Inserts an exclamation mark
  95.      \"                    Inserts a quote
  96.      \s                    Inserts the current selection
  97.      \d                    Inserts the current date (short format)
  98.      \D                    Inserts the current date (long format)
  99.  
  100.  
  101. So far so simple (?). Now for some more stuff...
  102.  
  103.  
  104.  
  105. Slightly More Difficult Stuff:
  106. -------------------------------------------------------------------------
  107. I guess I'm lazy, but I thought I'd add a few extra things to help me
  108. when I am marking up. So the next thing to learn about are the 'commands'
  109. that you can insert into your style definition.
  110.  
  111. The commands simply allow you to manipulate and edit the current
  112. selection in much the same way that you might do manually. Stringing a
  113. series of commands together can allow you to perform quite complex tasks.
  114.  
  115. Again, we'll work through an example. The previous example relied
  116. upon you selecting the text to be marked up. Much easier would be to
  117. simply click in the text, and have your definition automatically select
  118. the text for you.
  119.  
  120. So, referring back to the previous example, if we clicked in the middle
  121. of the word 'heading', we might want to select the whole line before
  122. applying the markup to it.
  123.  
  124. This is done using the command "!SL" (without the quotes). This reads as
  125.  
  126.         !    <--    The next 2 characters represent a command and parameter
  127.         S     <--    'Select' command
  128.         L    <--    This parameter means select the current line.
  129.         
  130. So the new definition would be:
  131.  
  132.    !SL<H2><I>...</I></H2>\r<HR>
  133.  
  134. Which reads as 'select the line, insert the '<H2><I>' bits before
  135. the current selection, and insert  '</I></H2>' and a return character and
  136. '<HR>' after the selection. (Hopefully you are still with me - there's more!).
  137.  
  138. However, a better way of doing it now that you've broken the ice with using
  139. the commands is to stop using the ellipsis format, and try something like...
  140.  
  141.     !SL !IR"<H2><I>\s</I></H2>\r<HR>"
  142.         ****       **               *
  143.  
  144. This reads pretty well as before, but the new bits (marked with an *) are..
  145.  
  146.     !IR"xxx"        Insert the following string, replacing the current selection.
  147.     \s                places the current selection into the specified string.
  148.  
  149.  
  150.  
  151.  
  152. List of Commands:
  153.  
  154. Command            Function
  155. =======         ========
  156. Selecting
  157.     !SW            select the word that the insertion point is in
  158.     !SL            select the line that the insertion point is in
  159.     !SP            select the paragraph that the insertion point is in
  160.     !SD            select the whole document.
  161.     !SC            select all text and tags of a Container.
  162.     !ST            select all Text within a container.
  163.     
  164.  
  165. Copying
  166.     !CC            copy the current selection to the clipboard
  167.     !CB            copy the current selection to the Buffer.
  168.     !CA            append the current selection to the clipboard
  169.     !CT"xyz"    append the text 'xyz' to the clipboard (all the placeholders
  170.                 mentioned above can be used in this string).
  171.     !CZ            clear the clipboard
  172.  
  173. Extending
  174.     !EF"xyz"    extends the selection forwards to start of string "xyz"
  175.     !E^            extend to start of line
  176.     !E$            extend to end of line
  177.     !E#"nnn"    extend selection by nnn characters. Value can be positive or negative
  178.  
  179. Inserting
  180.     !IS"xyz"    insert text "xyz" at start of selection
  181.     !IE"xyz"    insert text "xyz" at end of selection
  182.     !IR"xyz"    insert "xyz" Replacing the selection
  183.  
  184. Finding
  185.     !FN"abc"    find next occurrence of "abc" where "abc" can include the
  186.                 simple wildcards...
  187.                 '.'     matches any character
  188.                 '#'     matches any numeric character
  189.                 
  190.     !FA"abc"    same as above, but will find all matches of "abc" in the
  191.                 document, and will invoke subsequent commands in the segment for all found
  192.                 occurrences.
  193.                 
  194.                 It will probably be useful to quickly explain the logic of this command.
  195.                 Effectively it works as...
  196.                 
  197.                     repeat while "abc" is found
  198.                         ...segment commands
  199.                     end repeat
  200.                     
  201.                 If the search string isn't found, then any following commands in the
  202.                 segment will be skipped, and control will pass to the next segment. 
  203.                 (Information about segments can be found later in this document.)
  204.                 
  205.     !FS"xyz"    extends the selection forwards to start of string "xyz"
  206.  
  207.                      
  208. Place Insertion Point
  209.     !@E            insertion point at end of selection
  210.     !@S            insertion point at start of selection
  211.     !@T            insertion point at top of document
  212.     !@B            insertion point at bottom of document
  213.     !@L            insertion point at next line
  214.     !@P            insertion point at next paragraph
  215.     !@^            insertion point at start of line
  216.     !@$            insertion point at end of line
  217.     
  218. Case
  219.     !KR            raise the case of the selection
  220.     !KL            lower the case of the selection
  221.     !KT            make all HTML tags upper case
  222.     !KW            capitalize words.
  223.  
  224. Deleting
  225.     !DS            delete the current selection
  226.     !DX            delete current selection + surrounding space
  227.     !DC            delete the clipboard
  228.     
  229. Misc
  230.     !BP            Beep - useful in some cases when you are debugging a macro.
  231.     !§k            Switch searching case sensitivity ON
  232.     !§K            Switch searching case sensitivity OFF (Default)
  233.  
  234. Note that you can use Command-. to exit from any series of commands
  235. you may be using.
  236.  
  237. *    Commands may have a single space between them to aid legibility.
  238.  
  239. *    The sequence of commands is limited to 255 characters in length.
  240.  
  241. A good example of using the commands is having a list of delegate names
  242. for a conference. I want to have a main document with all the names, but
  243. have links from the names to vanity pages for each of them. In addition,
  244. I would like the names to be anchors. The names of the vanity pages are
  245. all in the format surname.html in a directory called 'vanity', and using
  246. the surname for the anchor name. eg:
  247.  
  248. Before:                After:
  249.  
  250. Joe Bloggs            <A NAME="Bloggs" HREF="/vanity/Bloggs.html">Joe Bloggs</A>
  251. University of X        University of X
  252. email: user@host    email: user@host
  253.  
  254.  
  255. This would normally require a fair bit of mouse and keyboard work to do,
  256. especially for a ist of 30 or so delegates. Better still would be to
  257. create a style definition that would do it all for me. eg:
  258.  
  259.     !SW!CC!SL!IS"<A NAME=\"\c\" HREF=\"/vanity/\c.html\">"!IE"</A>"
  260.     
  261. Assuming that I have clicked anywhere in the surname (ie 'Bloggs'),
  262. this definition reads as:
  263.  
  264.     !SW                    Select the Word (ie 'Bloggs')
  265.     !CC                    Copy the selection
  266.     !SL                    Select the Line.
  267.     !IS"<A NAME=\"        insert this text before the selection (note '\"' is
  268.                         required to enter a quote.)
  269.     \c                    insert the clipboard (ie 'Bloggs)
  270.     \" HREF=\"/vanity/    insert this text
  271.     \c                    again, insert the clipbaord
  272.     .html\">"            insert this text
  273.     !IE"</A>"            and insert this text after the selection to finish off.
  274.  
  275.  
  276. So, it doesn't look pretty, but it can be quite useful. If you want
  277. anything more powerful, then you really need to get stuck into GREP or
  278. PERL.
  279.  
  280. To recognise that you sometimes want to follow one style with
  281. another, you can tell your definition which definition to use next.
  282.  
  283. Using the above example, I could have the definition just described to
  284. mark up the name. I might then wish to have another definition to mark up
  285. the email address. By adding !N2 in front of the first definition, the
  286. next time the tool is used, definition 2 will be the default. (and if
  287. _that_ definition includes a !N1, then repeated use of the tool will
  288. cycle through these definitions 1 and 2.)
  289.  
  290.  
  291. Obfuscation time...
  292. -------------------------------------------------------------------------
  293.  
  294. There will be occasions when you want to perform a series of tasks. You
  295. could allocate them all to different macros, but if they are all meant to
  296. work together, this would be a waste of space.
  297.  
  298. You can therefore string together seqences of commands into 'segments'
  299. within a definition. To delineate a segment, type a bullet (option-8).
  300. You will see that the next segment will start on a new line, and be prefixed
  301. by a bullet.
  302.  
  303. A simple example of this in use would be the situation where you wanted
  304. to compile a list of all anchors in your document. The list will be
  305. compiled on the clipboard, so the first thing you would need to do is to
  306. clear it of any current text.
  307.  
  308. You will then want to find all anchors, so search for all text starting
  309. with "<A " and ending with "</A>". If it is found, it will be selected,
  310. and we want to append the selection and a return (so that all anchors
  311. start on a new line) to the clipboard. You then need to move the
  312. insertion point to the end of the selection so that the next iteration
  313. won't simply select the same part again. Just to illustrate the point
  314. further, when this second sequence has finished, we want to beep to
  315. signify that we have come to the end.
  316.  
  317. The macro itself...
  318.  
  319.         !DC
  320.         •!FA"<A .*</A>" !CT"\s\r"!@E
  321.         •!BP
  322.  
  323. Note that there are three segments here - the first one that deletes the
  324. clipboard only wants to be performed once. The newline and bullet
  325. delineate the second segment, which iterates through the document
  326. finding and appending the data to the clipboard. Only when this has
  327. complete will the third segment be invoked, and the machine will beep.
  328.  
  329. Note the use of !@E to move the insertion point to the end of the selection.
  330. Without this, the Find command will start searching again from the start of
  331. the current selection, and will of course immediately find itself again!
  332.  
  333.  
  334. Examples
  335. -------------------------------------------------------------------------
  336.  
  337. Well, that's probably clear as mud, so here are some examples:
  338.  
  339.  
  340. -------------------------------------------------------------------------
  341. •  To embolden a word (just click anywhere in the word you want to
  342.    embolden)
  343.  
  344.     !SW !IS"<B>" !IE"</B>"        Select the word, insert <B> at the start of the
  345.                                 selection, insert </B> at the end of the selection.
  346.                                 
  347. alternatively...
  348.  
  349.     !SW !IR"<B>\s</B>"            Select word, insert string which includes the current
  350.                                 selection between the tags.
  351.                     
  352. -------------------------------------------------------------------------
  353. •  To embolden a line:
  354.  
  355.     !SL !IS"<B>" !IE"</B>"        Exactly the same, but we use !SL instead of !SW.
  356.                     
  357. -------------------------------------------------------------------------        
  358. •  To add paragraph tags to a paragraph:
  359.  
  360.     !SP !IR"<P>\s</P>"            Select paragraph, insert <P> container around selection.
  361.     
  362. -------------------------------------------------------------------------
  363. •  To make a word into a named anchor:
  364.  
  365.     !SW !CC !IS"<A NAME="\c">" !IE"</A>"
  366.     
  367.     Select the word, copy it, insert the tag, inserting the clipboard between the quotes,
  368.     and inserting the closing tag at the end of the selection.
  369.  
  370. -------------------------------------------------------------------------
  371. •  To remove the current tags from around some text:
  372.  
  373.     !ST !CC !SC !IR"\c"        Select text up to tags, copy it, select containing tags
  374.                             as     well, insert replacing the selection with what was
  375.                             just copied.
  376.     
  377. -------------------------------------------------------------------------
  378. •  To mark up glossary items (which are on consecutive lines):
  379.  
  380.         !SL !IS"<DT>" !FN"\r" !@E !IS"<DD>"
  381.         
  382.         Select line, Insert "<DT>" at the start of the selection, Find the next
  383.         return character, move the insertion point after it, insert "<DD>" at
  384.         the insertion point.
  385.                             
  386. -------------------------------------------------------------------------
  387. •  Copy all lines containing "BBEdit" to the clipboard
  388.  
  389.         !CZ                                    Clear the clipboard
  390.         •!FA"BBEdit" !SL !CT"\s\r"            Find all occurrences of "BBEdit",
  391.                                             Select the line, Copy-append Text containing
  392.                                             the current selection and a carriage return.
  393.                                             
  394. -------------------------------------------------------------------------
  395. •  Copy all lines containing "BBEdit", case significant, to the
  396. clipboard
  397.  
  398.         !CZ!§k                                Clear the clipboard, set case switch ON
  399.         •!FA"BBEdit" !SL !CT"\s\r" !@E        Find all occurrences of "BBEdit",
  400.                                             Select the line, Copy-append Text containing
  401.                                             the current selection and a carriage return.
  402.                                             Then move cursor to end of found text ready
  403.                                             for next iteration.
  404.                                             
  405. -------------------------------------------------------------------------
  406. •  Compile and Insert a list of all the headings in a document
  407.  
  408.         !CZ!@T
  409.         •!FN"<MENU>"!@S!FS"/MENU>"!FS"\r"!DS
  410.         •!FA"<H#>"!@E!ST!CB!CT"<LI>\t<A HREF=\"#\b\">\b</A>\r"
  411.         •!@T!FN"</H1>"!@E!IS"\r<MENU>\r\c</MENU>"!B3
  412.  
  413.  
  414. -------------------------------------------------------------------------
  415. •  To change the title of your document to word capitalization
  416.  
  417.         !@T !FN"<TITLE>" !ES"</TITLE>" !KW    Move insertion point to the top of the doc.
  418.                                             Find next occurrence of <TITLE>. Extend
  419.                                             selection to "</TITLE>", change case of
  420.                                             selection to Word Capitalization.
  421.  
  422.  
  423.  
  424. (Last updated: 2/8/95)
  425.  
  426.  
  427. Lindsay Davies, 
  428. email:    Lindsay.Davies@sheffield.ac.uk
  429.